package com.seckill.activemq;

import org.apache.activemq.ScheduledMessage;
import org.springframework.jms.core.MessagePostProcessor;

import javax.jms.JMSException;
import javax.jms.Message;

/**
 * @author yjw
 * @date 2022/3/20 17:21
 */
public class ScheduleMessagePostProcesser implements MessagePostProcessor {

    private final long delay;

    public ScheduleMessagePostProcesser(long delay) {
        this.delay = delay;
    }

    @Override
    public Message postProcessMessage(Message message) throws JMSException {
        if (delay > 0) {
            //消息延时发送的时间
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
        }
        return message;
    }


}
